package com.woniuxy.oa.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.oa.entity.Attendance;
import com.woniuxy.oa.entity.PageBean;
import com.woniuxy.oa.mapper.AttendanceMapper;
import com.woniuxy.oa.service.AttendanceService;

@Service("attendanceService")
public class AttendanceServiceImpl implements AttendanceService{
	
	@Autowired
	AttendanceMapper AttendanceMapper;

	public void setAttendanceMapper(AttendanceMapper AttendanceMapper) {
		this.AttendanceMapper = AttendanceMapper;
	}
	
	//签到
	@Override
	public int insertSignIn(Attendance attendance) {
		int signIn = AttendanceMapper.insertSignIn(attendance);
		return signIn;
	}

	@Override
	public int updateSignBack(Attendance attendance) {
		int signBack = AttendanceMapper.updateSignBack(attendance);
		return signBack;
	}

	@Override
	public String selectIsSignIn(Attendance attendance) {
		String isSignIn = AttendanceMapper.selectIsSignIn(attendance);
		return isSignIn;
	}

	@Override
	public String selectIsSignBack(Attendance attendance) {
		String isSignBack = AttendanceMapper.selectIsSignBack(attendance);
		return isSignBack;
	}

	@Override
	public int lateReason(Attendance attendance) {
		int lateReason = AttendanceMapper.lateReason(attendance);
		return lateReason;
	}

	@Override
	public Attendance selectAllAttendanceByDateAndUserid(Attendance attendance) {
		Attendance attendances = AttendanceMapper.selectAllAttendanceByDateAndUserid(attendance);
		return attendances;
	}
	
	//根据考勤日期分页查询
	@Override
	public PageBean<Attendance> getAttendanceConditionByPage(int pageIndex, int pageSize, String startDate,
			String endDate) {
		//查询总记录条数
		int totalRecord = AttendanceMapper.selectAttendancesByTotalPageRecored(startDate,endDate);
		System.out.println("总记录条数为："+totalRecord);
		
		//查询每一页attendance数据
		List<Attendance> attendances = AttendanceMapper.selectAttendanceByPage((pageIndex-1)*pageSize, 
				pageSize, startDate,endDate);
		System.out.println("每一页展示的客户信息：\n"+attendances);
		
		//根据不同条件查询相关customer信息，并分页展示
		PageBean<Attendance> pageBean = new PageBean<Attendance>();
		pageBean.setBeanList(attendances);
		pageBean.setPageIndex(pageIndex);
		pageBean.setPageSize(pageSize);
		pageBean.setTotalRecord(totalRecord);
		pageBean.setPageBeginAndPageEnd();
		System.out.println("封装分页数据：\n"+pageBean);
		return pageBean;
	}
	
}
